/*
    7. Write a program in C to count total number of alphabets, digits and special characters in a string. 

    Test Data :
    Input the string : Welcome to w3resource.com

    Expected Output :

    Number of Alphabets in the string is : 21 
    Number of Digits in the string is : 1 
    Number of Special characters in the string is : 4
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char* getStr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getStrLen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

void countNum(char *p)
{
    int a = 0, d = 0, s = 0;
    char *str = p;
    while(*str != '\0'){
        if(isalpha(*str)){
            a++;
        }else if(isdigit(*str)){
            d++;
        }
        str++;
    }
    s = getStrLen(p) - a - d;
    printf("Number of Alphabets in the string is : %d\n", a);
    printf("Number of Digits in the string is : %d\n", d);
    printf("Number of Special characters in the string is : %d", s);
}

int main(void)
{
    char *str = malloc(1024);
    printf("Input the string : ");
    getStr(str);
    countNum(str);
    return 0;
}